//
//  CourseTeacherHeaderCell.m
//  ShowYork
//
//  Created by hxh on 2020/9/2.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "LessonTeacherHeaderCell.h"

@interface LessonTeacherHeaderCell ()
@property (nonatomic,strong)UIView *toolView;
@property (nonatomic,strong)UIImageView *teacherImgView;
@property (nonatomic,strong)UIImageView *iconImgView;
@property (nonatomic,strong)UILabel *nameLb;
@property (nonatomic,strong)UILabel *introLb;
@property (nonatomic,strong)UILabel *inrolTitleLb;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UILabel *classCount;
@property (nonatomic,strong)UILabel *studyCount;
@property (nonatomic,strong)UILabel *classLb;
@property (nonatomic,strong)UILabel *studyLb;
@property (nonatomic,strong)UIView *bottomLine;
@end

@implementation LessonTeacherHeaderCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
    
    self.teacherImgView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.teacherImgView];

    self.nameLb = [[UILabel alloc]init];
    self.nameLb.textColor = [UIColor whiteColor];
    self.nameLb.font = font(18);
    [self.contentView addSubview:self.nameLb];
    
    self.iconImgView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.iconImgView];
    
    self.introLb = [[UILabel alloc]init];
    self.introLb.numberOfLines = 0;
    self.introLb.textColor = [UIColor whiteColor];
    self.introLb.font = font(12);
    [self.contentView addSubview:self.introLb];
    
    self.toolView = [[UIView alloc]init];
    self.toolView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.toolView];
    
    [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.teacherImgView.mas_bottom).offset(-16);
        make.height.mas_equalTo(66);
        make.left.right.equalTo(self.contentView);
    }];
    
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.line];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(0.5);
        make.centerX.equalTo(self.toolView);
        make.top.equalTo(self.toolView).offset(20);
        make.bottom.equalTo(self.toolView).offset(-20);
    }];
    
    self.studyLb = [[UILabel alloc]init];
    self.studyLb.textColor = RGBA(102, 102, 102, 1);
    self.studyLb.text = @"学习次数";
    self.studyLb.font = font(12);
    self.studyLb.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.studyLb];
    
    [self.studyLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kScreenW/2);
        make.centerY.equalTo(self.toolView).offset(15);
        make.right.equalTo(self.toolView);
    }];
    
    self.classLb = [[UILabel alloc]init];
    self.classLb.textColor = RGBA(102, 102, 102, 1);
    self.classLb.text = @"课程数量";
    self.classLb.font = font(12);
    self.classLb.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.classLb];
    
    [self.classLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kScreenW/2);
        make.centerY.equalTo(self.toolView).offset(15);
        make.left.equalTo(self.toolView);
    }];
    
    self.classCount = [[UILabel alloc]init];
    self.classCount.textColor = RGBA(51, 51, 51, 1);
    self.classCount.font = font(18);
    [self.contentView addSubview:self.classCount];
    [self.classCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.classLb);
        make.centerY.equalTo(self.toolView).offset(-5);
    }];
    
    self.studyCount = [[UILabel alloc]init];
    self.studyCount.text = @"8";
    self.studyCount.textColor = RGBA(51, 51, 51, 1);
    self.studyCount.font = font(18);
    [self.contentView addSubview:self.studyCount];
    [self.contentView addSubview:self.classCount];
    [self.studyCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.studyLb);
        make.centerY.equalTo(self.toolView).offset(-5);
    }];
    
    self.bottomLine = [[UIView alloc]init];
    self.bottomLine.backgroundColor = RGBA(230, 230, 230, 1);
    [self.contentView addSubview:self.bottomLine];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self.toolView);
        make.height.mas_equalTo(0.5);
    }];
    
    [self.teacherImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(kScreenW/4*3);
    }];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.teacherImgView);
        make.left.mas_equalTo(self.contentView).offset(16);
    }];
    
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.nameLb);
        make.left.mas_equalTo(self.nameLb.mas_right).offset(8);
    }];
    
    [self.introLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(16);
        make.top.mas_equalTo(self.nameLb.mas_bottom).offset(12);
        make.width.mas_equalTo(KScaleWidth(152));
    }];
    
}

- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.toolView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15, 15)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.toolView.bounds;
    maskLayer.path = maskPath.CGPath;
    self.toolView.layer.mask = maskLayer;
}
- (void)setTeacherModel:(LessonTeacherModel *)teacherModel{
    _teacherModel = teacherModel;
    self.introLb.text = teacherModel.intro;
    self.nameLb.text = teacherModel.name;
    [self.teacherImgView sd_setImageWithURL:[NSURL URLWithString:teacherModel.photo]];
    if (teacherModel.viewCount.intValue >= 10000) {
        NSInteger count = teacherModel.viewCount.intValue;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.studyCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.studyCount.text = [NSString stringWithFormat:@"%@",teacherModel.viewCount];
    }
    if (teacherModel.lessonCount.intValue >= 10000) {
        NSInteger count = teacherModel.lessonCount.intValue;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.classCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.classCount.text = [NSString stringWithFormat:@"%@",teacherModel.lessonCount];
    }
    if (teacherModel.subResultId.intValue == 1) {
        self.iconImgView.image = [UIImage imageNamed:@"course_tag_chinese"];
    }
    if (teacherModel.subResultId.intValue == 2) {
        self.iconImgView.image = [UIImage imageNamed:@"course_tag_math"];
    }
    if (teacherModel.subResultId.intValue == 3) {
        self.iconImgView.image = [UIImage imageNamed:@"course_tag_english"];
    }
}



@end
